﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WxApiLib.Messages;

namespace WxApiLib.Handlers
{
    /// <summary>
    /// 文本信息处理类
    /// </summary>
    public class IMGTextHandler : IHandler
    {
        /// <summary>
        /// 请求的XML
        /// </summary>
        private string RequestXml { get; set; }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="requestXml">请求的xml</param>
        public IMGTextHandler(string requestXml)
        {
            this.RequestXml = requestXml;
            
        }
        /// <summary>
        /// 处理请求
        /// </summary>
        /// <returns></returns>
        public string HandleRequest()
        {

            string response = string.Empty;
            IMGTextMessage tm = IMGTextMessage.LoadFromXml(RequestXml);


            NetLog.WriteTextLog("图片消息", tm.FromUserName + ":" + tm.PicUrl, DateTime.Now);


            string picurl = tm.PicUrl;
            string mediaid = tm.MediaId;
            if (string.IsNullOrEmpty(picurl))
            {
                response = "您什么都没输入，没法帮您啊，%>_<%。";
            }
            else
            {

                response = HandleOther(picurl);
       
            }
         //   tm.Content = response;
            //进行发送者、接收者转换
            string temp = tm.ToUserName;
            tm.ToUserName = tm.FromUserName;
            tm.FromUserName = temp;
            response = tm.GenerateContent();
            return response;
        }
        /// <summary>
        /// 处理其他消息
        /// </summary>
        /// <param name="tm"></param>
        /// <returns></returns>
        private string HandleOther(string requestContent)
        {
            string mediaid = requestContent;

            return mediaid;
        }
    }
}
